|
|
|
This declares a class Point
and defines an object apoint. You can think of a class definition as a
structure definition with functions (or ``methods''). Additionally, you
|
|
can specify the access
rights in more detail. For example, _x and _y are private, because elements
of classes are private as default. Consequently, we explicitly
|
|
must ``switch'' the access
rights to declare the following to be public. We do that by using the keyword
public followed by a colon: Every element following this
|
|
keyword are now accessible
from outside of the class.
|
|
Recall that a structure
struct is a combination of various data elements which are accessible from
the outside. We are now able to express a structure with help of
|
|
a class, where all elements
are declared to be public.
|
|
This is exactly what C++
does with struct. Structures are handled like classes. Whereas elements of
classes (defined with class) are private by default, elements
|
|
of structures (defined with
struct) are public. However, we can also use private: to switch to a private
section in structures.
|
|
|